package <%- service_pakcage %>.platform;

import act.controller.Controller;
import com.github.d925529.apidoc.ApiHttpMethod;
import com.github.d925529.apidoc.annotation.*;
import <%- domain_package %>.<%- ClassName %>;
import com.mk.interceptor.ITranslate;
import com.mk.util.S2;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.PostAction;
import org.osgl.mvc.annotation.PutAction;
import org.osgl.mvc.annotation.With;

import javax.inject.Inject;
import javax.validation.constraints.NotNull;

/**
 * 说明：<%- title %>后台服务
 * 作者：<%- user %> 
 * 日期：<%- time %> 
 * 版本：1.0.0
 */
@Controller("<%- className %>")
@Api(group = "pl",title = "<%- title %>服务", path = "/<%- className %>")
@SuppressWarnings("unused")
public class <%- ClassName %>Service extends BasePlatformService {
    @Inject
    private <%- ClassName %>.Mapper <%- className %>Mapper;


    @With({ILogin.class, ITranslate.class})
    @PostAction("add.json")
    @ApiMethod(title = "增加保存<%- title %>", path = "/add.json", method = ApiHttpMethod.POST)
    @ApiParam(name = "<%- className %>", title = "<%- title %>", type = <%- ClassName %>.class)
    @ApiReturn(description = "主键", type = String.class)
    public String add(@NotNull <%- ClassName %> <%- className %>) {
        String id = S2.UUID();
        <%- className %>.set<%- ids[0].Name %>(id);
        <%- className %>Mapper.insertTemplate(<%- className %>);
        return id;
    }


    @With({ILogin.class, ITranslate.class})
    @PutAction("update.json")
    @ApiMethod(title = "修改保存<%- title %>", path = "/update.json", method = ApiHttpMethod.PUT)
    @ApiParam(name = "<%- className %>", title = "<%- title %>", type = <%- ClassName %>.class)
    @ApiReturn(description = "修改了的数量", type = int.class)
    public int update(@NotNull <%- ClassName %> <%- className %>) {
        return <%- className %>Mapper.updateTemplateById(<%- className %>);
    }

    @With(ILogin.class)
    @GetAction("view.json")
    @ApiMethod(title = "查询指定<%- title %>", path = "/view.json", method = ApiHttpMethod.GET)
    @ApiParam(name = "id", title = "<%- title %>的主键", type = String.class)
    @ApiReturn(description = "<%- title %>", type = <%- ClassName %>.class)
    public <%- ClassName %> view(@NotNull String id){
        return <%- className %>Mapper.single(id);
    }
}
